package com.cskaoyan.bean.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Spliterator;

/**
 * @author: Fengyi
 * @description: 分页查找显示的adminvo
 * @time: 2021/7/8 21:07
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AdminListVo {

    /**
     * id : 6
     * username : yongganniuniu
     * avatar : '
     * roleIds : [1]
     */

    private int id;
    private String username;
    private String avatar;
    private List<Integer> roleIds = new ArrayList<>();


    public AdminListVo(int id, String username, String avatar, String roleId) {
        this.id = id;
        this.username = username;
        this.avatar = avatar;
        if(roleId.contains(",")){
            //多个元素[1, 2]
            String substring = roleId.substring(1, roleId.indexOf("]"));
            String[] split = substring.split(",");
            for (String s : split) {
                roleIds.add(Integer.parseInt(s.trim()));
            }
        }else {
            //只有一个元素 [2]
            int index = roleId.indexOf("]");
            String substring = roleId.substring(1, index);
            roleIds.add(Integer.parseInt(substring));
        }
    }

    public void setRoleIds(String roleId) {
        String[] split = roleId.split(",");
        for (String s : split) {
            roleIds.add(Integer.parseInt(s.trim()));
        }
    }
}
